﻿using System;
using System.Collections.Generic;
using Kugar.Tools.IM.Tencent.ServerSDK.Converts;
using Kugar.Tools.IM.Tencent.ServerSDK.Enums;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Kugar.Tools.IM.Tencent.ServerSDK
{
    [JsonConverter(typeof(IMMessageJsonConverter))]
    public abstract class IMMessageBase
    {
        public abstract MessageItemTypeEnum Type { get; }
        
        public static IMMessageBase Load(IEnumerable<JObject> msgBody)
        {
            return null;
        }
        
    }

    [JsonConverter(typeof(IMMessageJsonConverter))]
    public class Message_Text : IMMessageBase
    {
        public Message_Text()
        {
        }

        public Message_Text(string text)
        {
            this.Text = text;
        }

        public override MessageItemTypeEnum Type => MessageItemTypeEnum.Text;

        public string Text { set; get; }

    }

    [JsonConverter(typeof(IMMessageJsonConverter))]
    public class Message_Face : IMMessageBase
    {
        public Message_Face()
        {
        }

        public Message_Face(int index, string data = "")
        {
            this.Index = index;
            this.Data = data;
        }

        public int Index { set; get; }

        public string Data { set; get; }

        public override MessageItemTypeEnum Type => MessageItemTypeEnum.Face;

    }

    [JsonConverter(typeof(IMMessageJsonConverter))]
    public class Message_Image : IMMessageBase
    {
        public override MessageItemTypeEnum Type => MessageItemTypeEnum.Image;

        public int Format { set; get; }

        public string UUID { set; get; }

        public ImageItem SourceImage { set; get; }

        public ImageItem LargeImage { set; get; }

        public ImageItem Thumbnail { set; get; }

        public class ImageItem
        {
            public int Type { set; get; }

            public string Url { set; get; }

            public int Size { set; get; }

            public int Width { set; get; }

            public int Height { set; get; }
        }
    }

    [JsonConverter(typeof(IMMessageJsonConverter))]
    public class Message_Sound : IMMessageBase
    {
        public Message_Sound() { }

        public Message_Sound(string uUID, int size, int second)
        {
            UUID = uUID ?? throw new ArgumentNullException(nameof(uUID));
            Size = size;
            Second = second;
        }

        public override MessageItemTypeEnum Type => MessageItemTypeEnum.Sound;

        public string UUID { set; get; }

        public int Size { set; get; }

        public int Second { set; get; }
    }

    [JsonConverter(typeof(IMMessageJsonConverter))]
    public class Message_File : IMMessageBase
    {
        public Message_File() { }

        public Message_File(string uUID, int size, string url)
        {
            UUID = uUID ?? throw new ArgumentNullException(nameof(uUID));
            Size = size;
            Url = url;
        }

        public override MessageItemTypeEnum Type => MessageItemTypeEnum.Sound;

        public string UUID { set; get; }

        public int Size { set; get; }

        public string Url { set; get; }
    }

}